Method for distributing computing time in a computer system

ABSTRACT

The invention relates to a method for distributing computing time in a computer system on which run a number of partial processes or threads to which an assignment process or scheduler assigns computing time as required, priorities being associated with individual threads and the assignment of computing time being carried out according to the respective priorities. According to said method, the individual threads are respectively associated with a number of time priority levels. A first time priority level contains threads to which computing time is assigned as required at any time. A first scheduler respectively allocates a time slice to the individual time priority levels, and respectively activates one of the time priority levels for the duration of the time slice thereof. A second scheduler monitors the threads of the first time priority level and the threads of the respectively activated time priority level, and assigns computing time to said threads according to the priorities thereof.

The invention relates to a method for distributing computation time in acomputer system which is mentioned in the preamble of claim 1.

The method according to the invention can be applied, in particular, tocomputer systems which process a number of tasks in the form ofcompeting subprocesses or “threads”. In this context, an activity or aprogram which is being executed is denoted as a “thread”. Also in commonuse for this are the terms of “task” or “process”; however, depending oncontext, these also implicitly include assumptions relating to furtherproperties such as, for example, the address space in which the programis running. These further properties are, however, of no importance forthe present invention.

An allocation process which is usually designated as a “scheduler”determines which thread comes to be executed, and when, that is to saywhich thread is allocated computation time or a processor. The scheduleris thus an algorithm which decides which thread comes to be executed,and when.

In such a computer system in which a number of mutually independenttasks can be processed in the form of threads, a thread can assumevarious states:

Computing: the thread has a computation time requirement and is beingexecuted, that is to say it has been allocated a processor.

Willing to compute: the thread is ready for execution and therefore hasa computation time requirement and is waiting for a processor to beallocated to it.

Blocked: the thread is not ready for execution and is waiting for anexternal event.

A thread goes over actively from the computing state into the blockedstate by calling up the operating system as appropriate. The change fromblocked to willing to compute happens through the onset of the externalevent, or the prompting of another thread, which undertakes anappropriate system call-up to this end. So that a thread willing tocompute can become computing, the scheduler needs to allocate it one ofthe available processors. Whenever a thread changes either

-   -   from the computing state into the blocked state, or    -   from the blocked state into the willing to compute state,    -   the scheduler is called up in order either to allocate the        processor becoming free a new process ready for computation, or        to withdraw the processor from one of the computing threads if        the thread becoming willing to compute is classified as more        important.

From the point of view of the scheduler, there are a number of threadswilling to compute which are competing for the allocation of aprocessor. It is assumed that the number of available processors isgenerally smaller than the number of threads ready for computation, thatis to say the scheduler normally finds more “competitors” for aprocessor than there are processors to be awarded.

A multiplicity of procedures are known as to how a scheduler can be usedto fix the thread to which a processor is allocated at a respectivepoint in time.

In the case of a first method, which is known as priority method,priorities are assigned to the individual threads. A thread ofrelatively high priority obtains preference over a thread of relativelylow priority. Depending on requirement, threads of the same priority areeither not admissible, or they are placed in a queue in the sequence inwhich they become willing to compute. Depending on requirements, thepriority of the individual threads can both be statistically fixed andbe dynamically determined and be continuously corrected.

In the case of the priority method, there is no possibility ofguaranteeing a thread a computation time allocation: threads having ahigh priority can occupy the processors as long as desired, and it canhappen in the extreme case that threads having a low priority neverbecome computing.

In a further method, which is also known as time slice method (roundrobin), the period of time for which a thread may use a processor islimited. As soon as a thread currently operating has used the processorallocated to it for more than a fixed duration (that is to say it has“consumed” its “time slice”), it is necessarily interrupted. In thiscase, the thread remains willing to compute, and is placed at the end ofa queue. Depending on requirements, the duration of the time slice canbe a constant or a thread-specific variable. This method requires anexternal timer which activates the operating system via an interrupt atspecific time intervals so that said operating system can monitor thetime consumed by the running thread and, if appropriate, can activatethe scheduler.

The time slice method enables the allocation of computation time, but itdoes not permit a rapid reaction to external events: in the mostunfavorable case, a thread which becomes willing to compute on the basisof an interrupt, for example, must wait for the entire cycle, that is tosay the time slices of all the other threads willing to compute, beforeit can become computing.

In many computer systems, in particular in computer systems having anumber of threads of which some are subject to real time requirements,however, at least these “real time threads” must be able to react toexternal events within a maximum time which is guaranteed and, ideally,as short as possible, that is to say they must be able to becomecomputing. At the same time, threads exist which require a minimumallocation of computation time in order to accomplish their respectiveactivities. It must also be possible to guarantee such a time allocationfor threads. Combinations of the above-named methods are correspondinglyknown.

In a method known from EP-A2-0658 841 groups of threads are assignedpriorities, and the individual threads are allocated computation timeinside the groups in a time slice method.

In a further method, known from EP-A2-880 059, the threads are groupedinto classes which are arranged in a hierarchy. Each class has a timefunction value which determines when the class is allocated computationtime. Within a level of the hierarchy, computation time priorities aredefined by one or more time-based functions which can be constant orchange dynamically.

The invention is based on the object of providing a method of the typementioned at the beginning which permits reliable statements relating tothe computation time due to individual threads, and in the case of whichcomputation time promised but then not taken up can be dynamicallyredistributed.

This object is achieved by means of the features specified in Patentclaim 1. Advantageous refinements and developments of the inventionfollow from the subclaims.

According to the invention, a method is provided for distributingcomputation time in a computer system on which there is running a numberof subprocesses or “threads” (N0, S0, P0, W1, W2) to which, if required,an allocation process or “scheduler” allocates computation time,individual threads (N0, S0, P0, W1, W2) being assigned priorities, andthe allocation of computation time being performed as a function of therespective priorities.

The method according to the invention is characterized

-   -   in that the individual threads are respectively assigned to a        number of time partitions,    -   in that a first of the time partitions includes threads which        are allocated computation time, if required, at any time,    -   in that a first scheduler respectively assigns the individual        time partitions a time slice, and respectively activates one of        the time partitions for the duration of its time slice,    -   and in that a second scheduler monitors the threads of the first        time partition and the threads of the respectively activated        time partition, and allocates these threads computation time as        a function of their priorities.

In accordance with one refinement of the invention, the first scheduleris a thread of the first time partition.

Here, preferably, threads of the first time partition which have a lowpriority additionally can obtain computation time of the respectivelyactivated further time partitions when the further time partitionsinclude no threads having a computation time requirement.

The first scheduler can be implemented as an endless loop and have ahigh priority.

The second scheduler is always called up whenever a thread registers orrelinquishes a computation time requirement.

In the case of the method according to the invention, it can thereby beensured that the reaction time of threads to external events always liesbelow an assured maximum time.

The invention is explained in yet more detail below with the aid ofexemplary embodiments illustrated in the drawing.

In the drawing:

FIG. 1 shows an exemplary embodiment of a flowchart of the first (timepartition) scheduler in accordance with the invention;

FIG. 2 shows an exemplary embodiment of a flowchart of the second(thread) scheduler in accordance with the invention;

FIG. 3 shows an illustration of an example of a scheduling cycle.

The method according to the invention combines the properties of thetime slice method and the priority method. As in the case of thepriority method, the threads have a priority as attribute. In addition,each thread willing to compute is assigned to a respective timepartition. A time partition therefore designates a quantity of threadswilling to compute with different priority, in general.

There is a specific first time partition, the so-called backgroundpartition. The threads which are assigned to the background partitioncan become computing at any time. It holds for all the remaining timepartitions that the threads assigned to them can only ever becomecomputing when the relevant time partition is “active”, it beingpossible, in addition to the background partition, for at most onefurther time partition to be active at any one time.

The method uses two primary schedulers: a first scheduler, designated astime partition scheduler, respectively assigns the various timepartitions a time slice, and activates one of the time partitions eachfor the duration of its time slice. A second scheduler, designated asthread scheduler, considers the union set of the threads of thebackground partition and the currently active partition, and allocatesthe available processors to the threads from this set which have thehighest priority.

The threads of the background partition have various functions,depending on their priority:

-   -   1. Threads of the background partition which have a high        priority can implement services which are to be jointly used by        threads of various other time partitions. Moreover, such threads        can take over tasks of the operating system such as, for        example, the monitoring of other threads or of the state of the        overall system. In particular, the time partition scheduler        itself can be implemented as a thread of the background        partition.    -   2. Threads of the background partition which have a relatively        low priority obtain computation time whenever the currently        active time partition has no threads willing to compute, that is        to say when the threads assigned to it do not call upon the time        allocation awarded to them, for example because they must wait        on external events. There is thus a possibility for computation        time that has been awarded and yet not called upon to be fed to        rational use.

FIG. 1 illustrates the mode of operation of a time partition scheduler10 with reference to a typical example. It is assumed here that the timepartitions of the system are to be activated cyclically, for a definedtime slice duration in each case. The time partition scheduler isimplemented in this example as an endless loop which runs as a thread ofhigh priority within the background partition. In step 20, the threadreads a list of time partitions with the associated time slicedurations. For each list element, the designated time partition isfirstly activated in step 30, and in step 40 the thread subsequentlyblocks for the duration of the time slice of the time partition justactivated. A check is made in step 50 as to whether the end of the listhas been reached. If the end of the list has not yet been reached, thenext element is selected from the list in step 70. If the end of thelist has been reached, the processing begins anew at the start via step60.

An exemplary embodiment of the thread scheduler 110 is shown in FIG. 2.The thread scheduler is called up whenever the state of a thread changesfrom computing to blocked, or when a previously blocked thread assumesthe state of willing to compute (for example on the basis of an externalevent), this being established in step 120. In the first case, it isnecessary in step 130 for the newly blocked thread to be removed fromthe set of threads willing to compute of the time partition assigned toit, whereas in the second case all currently computing threads remainwilling to compute in step 140. Subsequently in step 150 the highestpriorities both of the currently active time partition and of thebackground partition are determined. If the maximum priority of thecurrently active time partition is above that of the backgroundpartition, in step 160 the thread of this time partition, which has thehighest priority, is transferred into the state of computing, whileotherwise the thread of the background partition which has the highestpriority is selected in step 170. The selected thread is subsequentlyactivated in step 180.

When the maximum priority of the currently active time partition isequal to the maximum priority of the background partition, thebackground partition is preferred in this example. It would equally wellbe possible here, as a function of the respective requirements, to givepreference to the currently active time partition.

An example of a scheduling cycle is shown in FIG. 3. This figure uses anexample to illustrate the way in which the method according to theinvention functions. It is assumed in this example that only oneprocessor is present. There are two time partitions Tau1 and Tau2 havingthe threads W1 and W2, and in addition there is the background partitionTau0. There are a thread of low priority named N0, a thread of averagepriority named S0, and a thread of high priority named P0 in Tau0.

Let P0 be the time partition scheduler in accordance with FIG. 1, thatis to say this thread becomes computing for a short time in each case inorder to switch over the active time partition, and subsequently blocksin each case for the duration of the time slice of the active timepartition (iT1 or T2 in FIG. 3).

Let S0 be a “server” which is used by W1 and W2 together and whichfurnishes services upon demand from these threads, and otherwise blocks.

Let N0 be a background thread which is continuously willing to computeand never blocks.

Neither of the two time partitions Tau1 and Tau2, respectively, isinitially active in the example. There are three threads willing tocompute: W1, W2 and N0. Since, however, the time partitions of W1 and W2are not active, these threads do not become computing despite theirrelatively high priority. N0 is the sole thread willing to compute inthe background partition Tau0 (P0 and S0 are blocked). Consequently, N0is initially computing. At the instant A, the time partition schedulerP0 becomes willing to compute and at the same time computing, since itspriority is above that of N0. P0 activates the time partition Tau1, andsubsequently blocks for the duration T1. Since Tau1 is now active, thethread W1 assigned to this time partition becomes willing to computeand, since its priority is above that of N0, it becomes computing. W1blocks at the instant B in order to await an external event. This eventoccurs at the instant C. The time between the instants B and C ispromised for the time partition Tau1, but there is no thread assigned toTau1 which could call upon this time. Consequently, this unused time isallocated to N0. After expiry of the time slice T1 of the partition Tau1at the instant D, the time partition scheduler P0 becomes computing. Itactivates the time partition Tau2 and subsequently blocks for theduration T2. Since Tau2 is now active, the thread W2 assigned to thistime partition becomes computing. At the instant E, W2 requests aservice from the server S0 and blocks in order to await its answer. S0thereupon becomes willing to compute and, since its priority is abovethat of N0, becomes computing. At the instant F, S0 has furnished therequested service, sends an appropriate notification to its user W2 andblocks while waiting for the next job. W2 thereupon becomes computingagain and operates up to the expiry of the time slice of its timepartition Tau2. At this point, the time partition scheduler P0 becomescomputing again and reactivates the background partition Tau0. The sameconditions as at the beginning of the cycle therefore prevail again.

1. Method for distributing computation time in a computer system onwhich there is running a number of subprocesses or “threads” to which,if required, an allocation process or “scheduler” allocates computationtime, individual threads being assigned priorities, and the allocationof computation time being performed as a function of the respectivepriorities, characterized in that the individual threads arerespectively assigned to a number of time partitions, in that a first ofthe time partitions includes threads which are allocated computationtime, if required, at any time, in that a first scheduler respectivelyassigns the individual time partitions a time slice, and respectivelyactivates one of the time partitions for the duration of its time slice,and in that a second scheduler monitors the threads of the first timepartition and the threads of the respectively activated time partition,and allocates these threads computation time as a function of theirpriorities.
 2. Method according to claim 1, wherein the first scheduleris a thread of the first time partition.
 3. Method according to claim 1,wherein threads of the first time partition which have a low priorityadditionally obtain computation time of the respectively activatedfurther time partitions when the further time partitions include nothreads having a computation time requirement.
 4. Method according toclaim 1, wherein first scheduler is implemented as an endless loop andhas a high priority.
 5. Method according to claim 1, wherein the secondscheduler is always called up whenever a thread registers orrelinquishes a computation time requirement.
 6. Method according toclaim 1, wherein the reaction time of threads to external events alwayslies below an assured maximum time.